package com.parkinglot.management.service.impl;

import com.baidu.aip.ocr.AipOcr;
import com.parkinglot.management.repository.EnteredCarInfoRepository;
import com.parkinglot.management.repository.entity.EnteredCarInfo;
import com.parkinglot.management.service.EnteredCarInfoService;
import com.parkinglot.management.util.DiscernCarNum;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class EnteredCarInfoServiceImpl implements EnteredCarInfoService {
    @Autowired
    DiscernCarNum discernCarNum;

    @Autowired
    EnteredCarInfoRepository enteredCarInfoRepository;
    @Override
    public EnteredCarInfo addEnteredCarInfo(String path, String timestamp) {
        String carNum = discernCarNum.getCarNumFromImg( path);
        EnteredCarInfo enteredCarInfo = new EnteredCarInfo();
        enteredCarInfo.setCarNum(carNum);
        enteredCarInfo.setEnterTime(timestamp);
        return enteredCarInfoRepository.save(enteredCarInfo);
    }

    @Override
    public void deleteEnteredCarInfo(EnteredCarInfo enteredCarInfo) {
        enteredCarInfoRepository.delete(enteredCarInfo);
    }

    @Override
    public List<EnteredCarInfo> getAllEnteredCarInfo() {
        return enteredCarInfoRepository.findAll();
    }

    @Override
    public List<EnteredCarInfo> getEnteredCarInfoByCarNum(String carNum) {
        return enteredCarInfoRepository.findAllByCarNum(carNum);
    }


}
